#! /usr/bin/env python
# coding=utf-8
# 数据库操作

#import md5
#m = md5.new()
#m.update(url)
#id = m.hexdigest()
from google.appengine.ext import db

class CronInfo(db.Model):
	title = db.StringProperty(required=True)
	url = db.StringProperty(required=True)
	enabled = db.BooleanProperty()
	sendSuccessMsg = db.BooleanProperty()
	sendFailMsg = db.BooleanProperty()
	minutes = db.ListProperty(long)
	hours = db.ListProperty(long)
	dayOfWeek = db.ListProperty(long)
	dayOfMonth = db.ListProperty(long)
	month = db.ListProperty(long)

def addCronInfo(cron):
	if cron:
		cron.put()

def updateCronInfo(cron):
	if cron:
		cron.put()

def deleteCronInfo(cron):
	if cron:
		cron.delete()

def getCronInfo(id):
	#rec = db.get(db.Key.from_path('CronInfo', id))
	#return rec
	cron = CronInfo.get_by_id(id)
	return cron

def listCronInfo():
	ls = []
	q = db.GqlQuery("select * from CronInfo")
	for r in q:
		ls.append(r)
	return ls


#def logAccess(desti, fro):
#    try:
#        db.run_in_transaction(incDestiCounter, desti)
#        db.run_in_transaction(incFroCounter, fro)
#        return True
#    except Exception:
#        return False
